package com.yanqu.road.dao.impl.activity.wealthscroll;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.wealthscroll.config.WealthScrollTaskConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class WealthScrollConfigDaoImpl extends TempDao {
    private static String getWealthScrollTaskConfigSql = "select * from `t_s_activity_wealth_scroll` where `activityId`=?";
    public Map<Integer,WealthScrollTaskConfig> getWealthScrollTaskConfigMap(int activityId) {
        Map<Integer,WealthScrollTaskConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getWealthScrollTaskConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                WealthScrollTaskConfig wealthScrollTaskConfig = new WealthScrollTaskConfig();
                wealthScrollTaskConfig.setActivityId(rs.getInt("activityId"));
                wealthScrollTaskConfig.setId(rs.getInt("id"));
                wealthScrollTaskConfig.setCompleteType(rs.getInt("completeType"));
                wealthScrollTaskConfig.setCompleteParams(rs.getString("completeParams"));
                wealthScrollTaskConfig.setRewards(rs.getString("rewards"));
                wealthScrollTaskConfig.setIsScheduleRewards(rs.getString("isScheduleRewards"));
                wealthScrollTaskConfig.setIsSpecialRewards(rs.getString("isSpecialRewards"));
                wealthScrollTaskConfig.setIsSuperRewards(rs.getString("isSuperRewards"));
                map.put(wealthScrollTaskConfig.getId(),wealthScrollTaskConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
